#pragma once
#ifndef MYDIRECT3DVERTEXBUFFER7_H
#define MYDIRECT3DVERTEXBUFFER7_H

#include "common.h"
#include <d3d.h>

class MyDirect3DVertexBuffer7 : public IDirect3DVertexBuffer7 {
public:
    MyDirect3DVertexBuffer7(IDirect3DVertexBuffer7* direct3DVertexBuffer7) : direct3DVertexBuffer7(direct3DVertexBuffer7) {
        DebugWrite("MyDirect3DVertexBuffer7::MyDirect3DDevice7\n");
    }

    inline void GetOriginal(IDirect3DVertexBuffer7** direct3DVertexBuffer7) {
        (*direct3DVertexBuffer7) = this->direct3DVertexBuffer7;
    }

    /*** IUnknown methods ***/
    HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObj) {
        DebugWrite("MyDirect3DVertexBuffer7::QueryInterface\n");
        return this->direct3DVertexBuffer7->QueryInterface(riid, ppvObj);
    }

    ULONG STDMETHODCALLTYPE AddRef() {
        DebugWrite("MyDirect3DVertexBuffer7::AddRef\n");
        return this->direct3DVertexBuffer7->AddRef();
    }

    ULONG STDMETHODCALLTYPE Release() {
        DebugWrite("MyDirect3DVertexBuffer7::Release\n");
        ULONG count = this->direct3DVertexBuffer7->Release();
        if (0 == count) {
            delete this;
        }

        return count;
    }

    /*** IDirect3DVertexBuffer7 methods ***/
    HRESULT STDMETHODCALLTYPE GetVertexBufferDesc(LPD3DVERTEXBUFFERDESC lpVBDesc) {
        DebugWrite("MyDirect3DVertexBuffer7::GetVertexBufferDesc\n");
        return this->direct3DVertexBuffer7->GetVertexBufferDesc(lpVBDesc);
    }

    HRESULT STDMETHODCALLTYPE Lock(DWORD dwFlags, LPVOID* lplpData, LPDWORD lpdwSize) {
        DebugWrite("MyDirect3DVertexBuffer7::Lock\n");
        return this->direct3DVertexBuffer7->Lock(dwFlags, lplpData, lpdwSize);
    }

    HRESULT STDMETHODCALLTYPE Optimize(LPDIRECT3DDEVICE7 lpD3DDevice, DWORD dwFlags);

    HRESULT STDMETHODCALLTYPE ProcessVertices(DWORD dwVertexOp, DWORD dwDestIndex, DWORD dwCount, LPDIRECT3DVERTEXBUFFER7 lpSrcBuffer, DWORD dwSrcIndex, LPDIRECT3DDEVICE7 lpD3DDevice, DWORD dwFlags);

    HRESULT STDMETHODCALLTYPE ProcessVerticesStrided(DWORD dwVertexOp, DWORD dwDestIndex, DWORD dwCount, LPD3DDRAWPRIMITIVESTRIDEDDATA lpVertexArray, DWORD dwSrcIndex, LPDIRECT3DDEVICE7 lpD3DDevice, DWORD dwFlags);

    HRESULT STDMETHODCALLTYPE Unlock() {
        DebugWrite("MyDirect3DVertexBuffer7::Unlock\n");
        return this->direct3DVertexBuffer7->Unlock();
    }

private:
    IDirect3DVertexBuffer7 *direct3DVertexBuffer7;
};

#endif
